﻿using System;
using System.Xml.Serialization;

using Fuse8.DomainFramework.Common;
using Fuse8.DomainFramework.Domain;

using Fuse8.ContentManagementFramework.SystemFacade.Extensions;

namespace Fuse8.ContentManagementFramework.Domain.Special
{
    [Serializable]
    public class CmsConfigurationItemContainer
    {
        public CmsConfigurationItem[] Items { get; set; }
    }

    [Serializable]
    public class CmsConfigurationItem : Int32EntityObject
    {
        public string Title { get; set; }

        public string Description { get; set; }

        public string ManagementUrl { get; set; }

        public string ImageUrl { get; set; }

        public override string ToString()
        {
            return this.StoreMe();
        }

        #region IEntityObject Members

        public override bool IsCreated
        {
            get
            {
                return false;
            }
        }

        public override bool IsNew
        {
            get
            {
                return true;
            }
        }

        public override string TypeParameter
        {
            get
            {
                return "CmsConfigurationItem";
            }
        }

        #endregion

        #region IEntityObject<int> Members

        [XmlIgnore]
        public override int Id { get; set; }

        public override void IncreaseId()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region Overrides base

        public override bool Equals(object obj)
        {
            Guard.ArgumentNotNull(obj, "obj");

            return GetHashCode().Equals(obj.GetHashCode());
        }

        public override int GetHashCode()
        {
            return string.Format("{0}{1}{2}{3}", Title, Description, ImageUrl, ManagementUrl).GetHashCode();
        }

        #endregion

        #region IEqualityComparer<IEntityObject<int>> Members

        public override bool Equals(IEntityObject<int> x, IEntityObject<int> y)
        {
            Guard.ArgumentNotNull(x, "x");
            Guard.ArgumentNotNull(y, "y");

            var tmpX = x as CmsConfigurationItem;
            var tmpY = y as CmsConfigurationItem;

            return tmpX.Title.Equals(tmpY.Title) &&
                tmpX.Description.Equals(tmpY.Description) &&
                tmpX.ImageUrl.Equals(tmpY.ImageUrl) &&
                tmpX.ManagementUrl.Equals(tmpY.ManagementUrl);
        }

        public override int GetHashCode(IEntityObject<int> obj)
        {
            Guard.ArgumentNotNull(obj, "obj");

            return obj.GetHashCode();
        }

        #endregion
    }
}
